classdef GaltonStrategyMV < TradingStrategy
    %This is an class for the Naive Markowitz trading strategies
    properties
       name =  {'Galton'};
       galtonCorrection;

     end
    
    methods
        function obj = strategyCalculate(obj, t, r_past, r_plus1, r_curr )
                
                post_window = obj.galtonCorrection.post_window;
                galton_coeffs = obj.galtonCorrection.galton_coeffs;
                %pre_window = obj.galtonCorrection.pre_window;

                basisMeans=mean(r_past)';
                cov_H=cov(r_past);
                corr_H=corr(r_past);
                var_H=diag(cov_H);    

                corr_Gal=nanmean(galton_coeffs(1:t-post_window,2,2,1))*corr_H + nanmean(galton_coeffs(1:t-post_window,1,2,1));
                corr_Gal(eye(size(corr_Gal))==1)=1;

                var_Gal=var_H*nanmean(galton_coeffs(1:t-post_window,2,3,1))+nanmean(galton_coeffs(1:t-post_window,1,3,1));
                var_Gal=max(var_Gal,0);

                cov_Gal=diag(var_Gal)^.5*corr_Gal*diag(var_Gal)^0.5;% the corrected covariance matrix

                k=min(eig(cov_Gal));

                if k<=0
                     cov_Gal = cov_Gal + eye(size(cov_Gal))*(-2*k);
                end

               miu_MRC=basisMeans*nanmean(galton_coeffs(1:t-post_window,2,4,1))+nanmean(galton_coeffs(1:t-post_window,1,4,1));
               weightsMV = obj.setMVStrategyParams(cov_Gal,miu_MRC);

               obj = obj.executeCommonElements(t,weightsMV,cov_Gal,miu_MRC, r_plus1,r_curr);                
               
        end
        
  

    end
    
end

